import Vue from 'vue'
import Router from 'vue-router'
import {
  resolve
} from 'url'

Vue.use(Router)

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [{
      path: '/register',
      component: resolve => {
        require(['./views/register/register.vue'], resolve)
      }
    },
    {
      path: '/login',
      component: resolve => {
        require(['./views/register/login.vue'], resolve)
      }
    },
    {
      path: '/forget',
      component: resolve => {
        require(['./views/register/forget.vue'], resolve)
      }
    },
    {
      path: '/resume/preview',
      component: resolve => {
        require(['./views/resume/resume-preview.vue'], resolve)
      }
    },
    {
      path: '/',
      component: resolve => {
        require(['./views/index.vue'], resolve)
      },
      children: [{
          path: '/index',
          component: resolve => {
            require(['./views/index/index.vue'], resolve)
          }
        },
        {
          path: '/job',
          component: resolve => {
            require(['./views/job/index'], resolve)
          }
        },
        {
          path: '/job/details',
          component: resolve => {
            require(['./views/job/details/index.vue'], resolve)
          }
        },
        {
          path: '/resume',
          component: resolve => {
            require(['./views/resume/index'], resolve)
          }
        },
        {
          path: '/send',
          component: resolve => {
            require(['./views/send/index'], resolve)
          }
        },
        {
          path: '/communication',
          component: resolve => {
            require(['./views/communication/index'], resolve)
          }
        },
        {
          path: '/setting',
          component: resolve => {
            require(['./views/setting/index'], resolve)
          },
          children: [{
              path: '/setting/binding',
              component: resolve => {
                require(['./views/setting/binding.vue'], resolve)
              }
            },
            {
              path: '/setting/password',
              component: resolve => {
                require(['./views/setting/password.vue'], resolve)
              }
            },
            {
              path: '/setting/privacy',
              component: resolve => {
                require(['./views/setting/privacy.vue'], resolve)
              }
            },
            {
              path: '/setting/bank',
              component: resolve => {
                require(['./views/setting/bank.vue'], resolve)
              }
            }
          ]
        },
        {
          path: '/about',
          component: resolve => {
            require(['./views/about/index.vue'], resolve)
          },
          children: [{
              path: '/about/1', //关于我们
              component: resolve => {
                require(['./views/about/ourselves.vue'], resolve)
              }
            },
            {
              path: '/about/2', //个人用户服务协议
              component: resolve => {
                require(['./views/about/companyflow.vue'], resolve)
              }
            },
            {
              path: '/about/3', //企业用户服务协议
              component: resolve => {
                require(['./views/about/enterprise.vue'], resolve)
              }
            },
            {
              path: '/about/4', //隐私政策
              component: resolve => {
                require(['./views/about/privacy.vue'], resolve)
              }
            },
            {
              path: '/about/5', //人才使用流程
              component: resolve => {
                require(['./views/about/talents.vue'], resolve)
              }
            }, {
              path: '/about/6', //企业招聘流程
              component: resolve => {
                require(['./views/about/personal.vue'], resolve)
              }
            },
            {
              path: '/about/7', //常见问题
              component: resolve => {
                require(['./views/about/problem.vue'], resolve)
              }
            },
            {
              path: '/about/8', //防骗指南
              component: resolve => {
                require(['./views/about/antifraud.vue'], resolve)
              }
            }
          ]
        }
      ]
    },
    {
      path: '*',
      component: resolve => {
        require(['./views/error.vue'], resolve)
      }
    }
  ],
  scrollBehavior(to, from, saveTop) {
    if (to.hash) {
      return {
        selector: to.hash
      }
    }
    if (saveTop) {
      return saveTop
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  }
})